<script setup lang="ts">

import {onMounted} from "vue";

onMounted(() => {
  // 初始更新时间
  updateTime();

// 每秒更新一次时间
  setInterval(updateTime, 1000);
})

function updateTime() {
  const now = new Date();
  document.getElementById('year').textContent = now.getFullYear();
  document.getElementById('month').textContent = String(now.getMonth() + 1).padStart(2, '0');
  document.getElementById('day').textContent = String(now.getDate()).padStart(2, '0');

  document.getElementById('hour').textContent = String(now.getHours()).padStart(2, '0');
  document.getElementById('minute').textContent = String(now.getMinutes()).padStart(2, '0');
  document.getElementById('second').textContent = String(now.getSeconds()).padStart(2, '0');
}
</script>

<template>
  <div class="compact-time">
    <div class="glow-corner corner-tl"></div>
    <div class="glow-corner corner-tr"></div>
    <div class="glow-corner corner-bl"></div>
    <div class="glow-corner corner-br"></div>

    <!-- 日期部分 -->
    <div class="time-part">
      <span class="time-value" id="year">2023</span>
      <span class="time-label">年</span>
    </div>
    <span class="time-separator">-</span>
    <div class="time-part">
      <span class="time-value" id="month">12</span>
      <span class="time-label">月</span>
    </div>
    <span class="time-separator">-</span>
    <div class="time-part">
      <span class="time-value" id="day">31</span>
      <span class="time-label">日</span>
    </div>

    <!-- 时间部分 -->
    <span class="time-separator" style="margin-left: 10px;">|</span>
    <div class="time-part">
      <span class="time-value" id="hour">23</span>
      <span class="time-label">时</span>
    </div>
    <span class="time-separator">:</span>
    <div class="time-part">
      <span class="time-value" id="minute">59</span>
      <span class="time-label">分</span>
    </div>
    <span class="time-separator">:</span>
    <div class="time-part">
      <span class="time-value pulse" id="second">59</span>
      <span class="time-label">秒</span>
    </div>
  </div>
</template>

<style scoped>
.compact-time {
  display: flex;
  align-items: center;
  height: 37px;
  padding: 0 20px;
  background: rgba(0, 20, 40, 0.7);
  border: 1px solid #00a2ff;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 162, 255, 0.3);
  font-family: 'Arial', sans-serif;
  color: #00f7ff;
  position: absolute;
  right: 4px;
  z-index: 1000;
  overflow: hidden;
}

.time-part {
  display: flex;
  align-items: baseline;
  margin: 0 5px;
}

.time-value {
  font-size: 28px;
  font-weight: bold;
  background: linear-gradient(to bottom, #ffffff, #00f7ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0 2px;
}

.time-label {
  font-size: 14px;
  color: #00a2ff;
  margin-left: 2px;
}

.time-separator {
  font-size: 24px;
  color: #00f7ff;
  margin: 0 2px;
}

.glow-corner {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 1px solid #00f7ff;
}

.corner-tl {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
}

.corner-tr {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
}

.corner-bl {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
}

.corner-br {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
}

@keyframes pulse {
  0% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.7;
  }
}

.pulse {
  animation: pulse 1.5s infinite;
}
</style>
